package com.api.shopapi.mapper;

import com.api.shopapi.entity.JKXueyang;
import com.api.shopapi.entity.dto.JKXueyangDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface JKXueyangMapper {


    @Insert("insert into jk_xueyang (JKXueyangCode,UserCode,XueYang,FromType,InspectTime,CreateTime) values " +
            "(#{jkXueyang.JKXueyangCode},#{jkXueyang.UserCode},#{jkXueyang.XueYang},#{jkXueyang.FromType}," +
            "#{jkXueyang.InspectTime},#{jkXueyang.CreateTime})")
    int insert(@Param("jkXueyang") JKXueyang jkXueyang);


    @Update("update jk_xueyang set UserCode=#{jkXueyang.UserCode},XueYang=#{jkXueyang.XueYang}," +
            "FromType=#{jkXueyang.FromType},InspectTime=#{jkXueyang.InspectTime},CreateTime=#{jkXueyang.CreateTime} " +
            "where JKXueyangCode=#{jkXueyang.JKXueyangCode}")
    int update(@Param("jkXueyang") JKXueyang jkXueyang);

    @Delete("delete from jk_xueyang where JKXueyangCode=#{jKXueyangCode}")
    int delete(@Param("jKXueyangCode") String jKXueyangCode);

    @Select("select * from jk_xueyang where JKXueyangCode=#{jKXueyangCode} limit 1")
    JKXueyang getByJKXueyangCode(@Param("jKXueyangCode") String jKXueyangCode);

    @Select("select * from jk_xueyang where UserCode=#{userCode} and InspectTime between #{startTime} and #{endTime} order by InspectTime desc")
    List<JKXueyang> getPageList(@Param("userCode") String userCode,@Param("startTime") String startTime,@Param("endTime") String endTime);

    @Select("<script>" +
            "select jx.*,u.Name as userName from jk_xueyang jx left join user u on jx.UserCode=u.UserCode " +
            "where u.GovernmentCode=#{governmentCode} " +
            "<if test ='name !=null and name!=\"\" '>" +
            "and u.Name like concat('%',#{name},'%') " +
            "</if>" +
            "and jx.InspectTime between #{startTime} and #{endTime} " +
            "order by jx.InspectTime desc" +
            "</script>")
    List<JKXueyangDTO> getAdmPageList(@Param("name") String name, @Param("governmentCode") String governmentCode, @Param("startTime") String startTime, @Param("endTime") String endTime);


}
